/************************************************************************
 *				SRLOS Team CopyRight
 *@file		mem_mmu.h
 *@author	bloceanc
 *@date		7/19/2010
 *@note		virtual memory management(page managerment)
 ************************************************************************/
 
#ifndef _MEM_MMU_H_
#define	_MEM_MMU_H_

#include "mt_mutex.h"

/*
 * process communication, share virtual page.
 * 		we allocate share page from kernel space, 
 * because brk can't controled well.so, have to share from ...
 */
typedef	struct _mmu_share_page{
	unsigned short	page_count;	// shared virtual page count
	unsigned short	process_count;	// indicate how many process share this page.
	unsigned int	vir_start_addr;	// page shared virtual startting address
	unsigned int	share_handle;	// share page handle. this value used to finding and specified by user!
	k_mutex access_mutex;	// Access mutex, when write data or read.
	struct _mmu_share_page *next;	// share page queue next.
	struct _mmu_share_page *prev;	// share page queue previous.
}process_share_page;

/*
 * mmu unit register context.
 * 	using this when exchanging tasks!
 * NOTE: There're 16 registers in CP15.We just save some 
 * 		of them for special using possible.
 * 		Current, this is just register 2--translation table base
 */
typedef struct _mmu_context_struct{
	unsigned int pt_phy_address;	/* physical address of base page table */
	unsigned int cache_state;	/* state of Data cache and Instrument cache */
}mmu_context;

/* 
 * memory structure of a process
 * all address fields in this structure must reside at 4KB boud!(describe page unit)
 * code section including global static area of process
 */
typedef	struct _mem_info_struct{
	unsigned int code_end;	/* end virtual address(4KB Bound) of code section
						* startting virtual address always static 0x40000000 */
	unsigned int brk_end;	/* end virtual address(4KB Bound) of heap section
						* startting virtual address always equal code_end field */
	unsigned int stack_start;	/* startting vritual address(4KB Bound) of stack section
							* end virtual address always static 0xffffffff	*/
	mmu_context mmu;	/* MMU register context */
}mem_info;

#endif	/** _MEM_MMU_H_ */
